package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.taotao.pojo.UploadPictureResult;
import com.taotao.service.PictureService;
import com.taotao.util.JsonUtils;

@Controller
public class UploadPicture {

	@Autowired
	private PictureService pictureService;

	/**
	 * 要求返回的数据是一个文本类型，要求content-type 为text/plan
	 * 
	 * @param uploadFile
	 * @return 为了兼容，要求返回的数据为文本类型 需要手动转换为String类型的
	 * @throws Exception
	 */
	// @RequestMapping("/pic/upload")
	// @ResponseBody
	// public UploadPictureResult uploadPicture(MultipartFile uploadFile)
	// throws Exception {
	// UploadPictureResult result = null;
	// result = pictureService.uploadPicture(uploadFile);
	// return result;
	// }
	// 兼容浏览器的写法
	@RequestMapping("/pic/upload")
	@ResponseBody
	public String uploadPicture(MultipartFile uploadFile)
			throws Exception {
		UploadPictureResult result = null;
		result = pictureService.uploadPicture(uploadFile);
		String json=JsonUtils.objectToJson(result);
		return json;
	}

}
